package com.situ.mall.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

// /page/admin/list
// /page/product/list
@Controller
@RequestMapping("/page")
public class PageController {

    @RequestMapping("/**")
    public String path(HttpServletRequest request) {
        // /page/admin/list
        // /page/product/list
        // /page/login
        String requestURI = request.getRequestURI();
        System.out.println("requestURI: " + requestURI);
        String[] paths = requestURI.split("/");
        // ["", "page", "admin", "list"]
        // ["", "page", "product", "list"]
        // ["", "page", "login"]
        if (paths.length == 4) {
            return paths[2] + "_" + paths[3];
        } else if (paths.length == 3) {
            return paths[2];
        } else {
            return "index";
        }
    }
}
